<!--
 * @author hemengxia
 活动管理-红包活动--参与情况
-->
<template>
  <section class="red-envelope-join-record">

    <el-collapse-transition>
      <section v-show="searchshow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model.trim="listQuery.userRealname"
          placeholder="输入姓名搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchshow = !searchshow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>
        </section>
      </section>
    </el-collapse-transition>
    <el-collapse-transition>
      <section v-show="!searchshow" class="main-search separate">
        <section class="search-inner">
          <el-row>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">姓名</div>
                <el-input
                  v-model.trim="search.userRealname"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入姓名搜索"
                />
              </section>
            </el-col>
            <el-col :span="8">
              <section class="search-inner-item">
                <div class="item-label">部门</div>
                <el-input
                  v-model.trim="search.deptName"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入部门搜索"
                />
              </section>
            </el-col>
            <!--            <el-col :span="8">
                          <section class="search-inner-item">
                            <div class="item-label">领取状态</div>
                            <el-select v-model="search.status" placeholder="请选择状态搜索" style="width: 80%;">
                              <el-option v-for="(item, index) in dict.HBHDLQZT" :key="index" :label="item.dictName"
                                         :value="item.dictValue"/>
                            </el-select>
                          </section>
                        </el-col>
                        <el-col :span="8">
                          <section class="search-inner-item">
                            <div class="item-label">红包状态</div>
                            <el-select v-model="search.expireStatus" placeholder="请选择状态搜索" style="width: 80%;">
                              <el-option v-for="(item, index) in dict.HBHDGQZT" :key="index" :label="item.dictName"
                                         :value="item.dictValue"/>
                            </el-select>
                          </section>
                        </el-col>
                        <el-col :span="12">
                          <section class="search-inner-item">
                            <div class="item-label">发放时间</div>
                            <el-date-picker
                                v-model="search.time"
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                clearable
                                :style="{width:'90%'}"
                                type="datetimerange"
                                format="yyyy-MM-dd HH:mm"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            />
                          </section>
                        </el-col>-->
          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchshow = !searchshow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </section>
      </section>
    </el-collapse-transition>

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>参与情况</span>
      </section>
      <section class="main-buttons-btns">
        <el-button class="filter-item" style="margin-left: 10px;" @click="handleExport">导出</el-button>
        <el-button style="padding: 10px 30px;" @click="handleCancel()">返回</el-button>
      </section>
    </section>
    <section class="main-table">
      <v-table
        :list="list"
        tag="gameActivityRecordList"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :selection="false"
      >
        <el-table-column label="操作" fixed="right" align="center" min-width="100" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </v-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </section>
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryRecord, exportMask, exportNoMask } from '../api/index'
import permission from '@/directive/permission/index.js'
import { exportSign } from '@/utils/fileImportOrExportSign'
import { exportCheck } from '@/utils/sensitiveInfoExportCheck'
import CryptoJS from '@/utils/aesJiaJM'
export default {
  name: 'GameActivityRecord',
  components: { Pagination, VTable },
  directives: { permission },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        userRealname: ''
      },
      searchshow: true,
      search: {
        userRealname: '',
        deptName: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      dict: {
        'HBHDLQZT': [],
        'HBHDGQZT': []
      },
      view: '/API-DOCUMENT/document/file/download?id=',
      link: '/survey?i=',
      previewStatus: false,
      obj: {},
      id: ''
    }
  },
  created() {
    this.id = this.$route.query.i
    /*  for (const i in this.dict) {
        this.getDict(i)
      }*/
    this.getList()
  },
  methods: {
    /**
     * 导出
     * @param row
     */
    handleExport() {
      const query = {
        activityBaseId: this.id
        // page: obj ? obj.page : this.listQuery.page,
        // pageSize: obj ? obj.limit : this.listQuery.limit
      }
      if (this.searchshow) {
        query['userRealname'] = this.listQuery.userRealname
      } else {
        query['userRealname'] = this.search.userRealname
        query['deptName'] = this.search.deptName
      }
      const obj = exportSign(query).obj

      exportCheck('STAFF_SERVICE_ACTIVITYADMIN', this.id, exportMask, exportNoMask, obj, '游戏活动参与情况.xlsx')
    },

    handleCancel() {
      this.$router.back()
    },

    /**
     * 查看详情
     * */
    handleDetail(row) {
      this.$router.push({ path: this.$filterPath('record/detail'), query: { i: this.id, userId: row.userId }})
    },

    filtercolumn(scope, item) {
      if (item === 'coverImgId') {
        return this.view + scope.row[item]
      } else	if (item === 'userIdnumber' || item === 'phoneNumber') {
        return CryptoJS.$aesJieM(scope.row[item])
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.userRealname = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        activityBaseId: this.id
      }
      if (this.searchshow) {
        query['userRealname'] = this.listQuery.userRealname
      } else {
        query['userRealname'] = this.search.userRealname
        query['deptName'] = this.search.deptName
        query['status'] = this.search.status
        query['expireStatus'] = this.search.expireStatus
        query['getTimeStart'] = this.search.time && this.search.time.length > 0 ? this.search.time[0] : ''
        query['getTimeEnd'] = this.search.time && this.search.time.length > 0 ? this.search.time[1] : ''
      }
      return new Promise((resolve, reject) => {
        queryRecord(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }

  }
}
</script>
<style lang="scss">

.red-envelope-join-record {
  padding: 0 10px 10px;

  .box-card {
    margin: 10px;
  }

  .main-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            &.el-date-editor input {
              padding-left: 30px;
            }

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }
}
</style>
